﻿using SaaS.Model.Entity.Gateways;
using SaaS.Model.Enums;
using System;
using System.ComponentModel.DataAnnotations;
using System.Web;
using XCore.Domain.Dto;

namespace SaaS.Model.Dto.Gateways
{
    public class NoticeInput : NoticeSetting, IEntityInput
    {
        public int? Id { get; set; }
        /// <summary>
        /// 标题，防注入
        /// </summary>
        private string _title;
        /// <summary>
        /// 标题
        /// </summary>
        [Required]
        [StringLength(128, ErrorMessage = "标题长度不能超过128个字符")]
        public string Title { get { return _title; } set { _title = HttpUtility.HtmlEncode(value); } }
        /// <summary>
        /// 内容，防注入
        /// </summary>
        private string _content;
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get { return _content; } set { _content = HttpUtility.HtmlEncode(value); } }
        /// <summary>
        /// 重要性
        /// </summary>
        public byte Importance { get; set; }
        /// <summary>
        /// 摘要，防注入
        /// </summary>
        private string _summary;
        /// <summary>
        /// 摘要
        /// </summary>
        [StringLength(512, ErrorMessage = "摘要长度不能超过512个字符")]
        public string Summary { get { return _summary; } set { _summary = HttpUtility.HtmlEncode(value); } }
        public ArticleStatus Status { get; set; }
        public NoticeType Type { get; set; }
        public DateTime? ReleaseTime { get; set; }

        private string _settingString;
        /// <summary>
        /// 配置信息，不可写
        /// </summary>
        public string SettingString
        {
            get
            {
                if (_settingString == null)
                {
                    _settingString = new NoticeSetting { Images = this.Images }.ToString();
                }
                return _settingString;
            }
        }
    }

}
